<?php
	require_once (dirname(__FILE__)."/config/Config.inc");
	require_once (dirname(__FILE__)."/config/api.inc");
	
	$parm = requestArrayParm($_REQUEST);
	
	unset($wheres);
	$wheres['id'] = $parm['id'];
	$chanpin =_SqlTool::getInfo('chanpin', $wheres);
	
	if(!empty($chanpin))
	{
		unset($where);
	
		$where['loginkey'] = $parm['loginkey'];
			
		$userinfo = _User::getUserInfo($where);
		
		if(!empty($userinfo))
		{
			if($chanpin['cp_style'] == '1')
			{
				//2. 首投产品，每个产品，用户仅能生成一条待确认投资记录，再次进行跳转时，不生成记录；当后台确认为【未投标】后，才能再次生成
				unset($query);
				$query['cp_id'] = $chanpin['id'];
				$query['userid'] = $userinfo['id'];
				$query['status'] = '1';
				$tzinfo =_SqlTool::getInfo('tzinfo', $query);
				if(empty($tzinfo))
				{
					unset($data);
					$data['phone'] = $userinfo['loginname'];
					$data['name'] = $userinfo['name'];
					$data['userid'] = $userinfo['id'];
					
					$data['pt_id'] = $chanpin['pt_id'];
					$data['cp_id'] = $chanpin['id'];
					$data['tztime'] = time();
					$data['status'] = '1';
					$data['cp_fllx'] = $chanpin['cp_fllx'];
					if($chanpin['cp_tzqxlx'] == 'day')
					{
						$days = $chanpin['cp_tzqx'];
						$data['endtime'] = strtotime("+$days days", strtotime(date('Y-m-d')));
					}
					
					if($chanpin['cp_tzqxlx'] == 'month')
					{
						$months = $chanpin['cp_tzqx'];
						$data['endtime'] = strtotime("+$months months", strtotime(date('Y-m-d')));
					}
					_SqlTool::addInfo('tzinfo', $data);
				}
			}
			
			if($chanpin['cp_style'] == '2')
			{
				//3. 复投产品，每个产品，每日，用户仅能生成一条待确认投资记录，再次进行跳转时，不生成记录；当后台确认为【未投标】后，才能再次生成
				unset($query);
				$query['cp_id'] = $chanpin['id'];
				$query['userid'] = $userinfo['id'];
				$between['start'] = strtotime(date('Y-m-d'));
				$between['end'] = strtotime(date('Y-m-d'))+86399;
				$query['status'] = '1';
				$tzinfo =_SqlTool::getList('tzinfo', $query,array(),array(),$between,'tztime');
				if(empty($tzinfo[0]))
				{
					unset($data);
					$data['phone'] = $userinfo['loginname'];
					$data['name'] = $userinfo['name'];
					$data['userid'] = $userinfo['id'];
					
					$data['pt_id'] = $chanpin['pt_id'];
					$data['cp_id'] = $chanpin['id'];
					$data['tztime'] = time();
					$data['status'] = '1';
					$data['cp_fllx'] = $chanpin['cp_fllx'];
					if($chanpin['cp_tzqxlx'] == 'day')
					{
						$days = $chanpin['cp_tzqx'];
						$data['endtime'] = strtotime("+$days days", strtotime(date('Y-m-d')));
					}
					
					if($chanpin['cp_tzqxlx'] == 'month')
					{
						$months = $chanpin['cp_tzqx'];
						$data['endtime'] = strtotime("+$months months",strtotime(date('Y-m-d')));
					}
					_SqlTool::addInfo('tzinfo', $data);
				}
			}
		}
		
		header("Location:".$chanpin['cp_tzlj']);
		
	}
